import {createRouter, createWebHistory} from 'vue-router'

const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes: [
        {
            path: '/auth',
            redirect: '/auth/login',
            component: () => import('@/views/auth/Index.vue'),
            children: [
                {
                    path: 'login',
                    name: 'login',
                    component: () => import('@/views/auth/Login.vue')
                },
                {
                    path: 'register',
                    name: 'register',
                    component: () => import('@/views/auth/Register.vue')
                }
            ]
        },
        {path: '/question', component: () => import('@/views/main/quiz/Question.vue')},
        {
            path: '/',
            redirect: '/home',
            component: () => import('@/views/main/Index.vue'),
            children: [
                {
                    path: 'home',
                    component: () => import('@/views/main/home/Index.vue')
                },
                {
                    path: 'quiz',
                    component: () => import('@/views/main/quiz/Index.vue'),
                },
                {
                    path: 'works',
                    component: () => import('@/views/main/works/Index.vue')
                },
                {
                    path: 'manage',
                    redirect: '/manage/user',
                    component: () => import('@/views/main/manage/Index.vue'),
                    children: [
                        {
                            path: 'user',
                            component: () => import('@/views/main/manage/user.vue'),
                        },
                        {
                            path: 'news',
                            component: () => import('@/views/main/manage/news.vue'),
                        },
                        {
                            path: 'works',
                            component: () => import('@/views/main/manage/works.vue'),
                        },
                        {
                            path: 'video',
                            component: () => import('@/views/main/manage/video.vue'),
                        },
                        {
                            path: 'quiz',
                            component: () => import('@/views/main/manage/quiz.vue'),
                        },
                        {
                            path: 'heir',
                            component: () => import('@/views/main/manage/heir.vue'),
                        }
                    ]
                }
            ]
        }
    ]
})

// 路由守卫
router.beforeEach((to, from, next) => {
    next()
});

export default router
